package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.HouseHost;
import com.ruoyi.system.service.IHouseHostService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 房东Controller
 * 
 * @author ruoyi
 * @date 2024-04-26
 */
@Controller
@RequestMapping("/system/host")
public class HouseHostController extends BaseController
{
    private String prefix = "system/host";

    @Autowired
    private IHouseHostService houseHostService;

    @RequiresPermissions("system:host:view")
    @GetMapping()
    public String host()
    {
        return prefix + "/host";
    }

    /**
     * 查询房东列表
     */
    @RequiresPermissions("system:host:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HouseHost houseHost)
    {
        startPage();
        List<HouseHost> list = houseHostService.selectHouseHostList(houseHost);
        return getDataTable(list);
    }

    /**
     * 导出房东列表
     */
    @RequiresPermissions("system:host:export")
    @Log(title = "房东", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HouseHost houseHost)
    {
        List<HouseHost> list = houseHostService.selectHouseHostList(houseHost);
        ExcelUtil<HouseHost> util = new ExcelUtil<HouseHost>(HouseHost.class);
        return util.exportExcel(list, "房东数据");
    }

    /**
     * 新增房东
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存房东
     */
    @RequiresPermissions("system:host:add")
    @Log(title = "房东", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(HouseHost houseHost)
    {
        return toAjax(houseHostService.insertHouseHost(houseHost));
    }

    /**
     * 修改房东
     */
    @RequiresPermissions("system:host:edit")
    @GetMapping("/edit/{hostId}")
    public String edit(@PathVariable("hostId") Long hostId, ModelMap mmap)
    {
        HouseHost houseHost = houseHostService.selectHouseHostByHostId(hostId);
        mmap.put("houseHost", houseHost);
        return prefix + "/edit";
    }

    /**
     * 修改保存房东
     */
    @RequiresPermissions("system:host:edit")
    @Log(title = "房东", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(HouseHost houseHost)
    {
        return toAjax(houseHostService.updateHouseHost(houseHost));
    }

    /**
     * 删除房东
     */
    @RequiresPermissions("system:host:remove")
    @Log(title = "房东", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(houseHostService.deleteHouseHostByHostIds(ids));
    }
}
